package com.hitqz.robot.biz.socket;

import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

/**
 * @author xupkun
 * @date 2024/6/12
 */
public class PowerSocketTest {

    public static void main(String[] args) throws IOException {
        try {
            String ip = "172.24.3.241"; int port = 10000;
            byte[] close2 = new byte[] {
                    (byte) 0xFE, 0x05, 0x00 , 0x01 , 0x00 , 0x00 , (byte) 0x88, 0x05
            };

            byte[] close3 = new byte[] {
                    (byte) 0xFE, 0x05 , 0x00 , 0x02 , 0x00 , 0x00 , 0x78 , 0x05
            };
            byte[] close4 = new byte[] {
                    (byte) 0xFE, 0x05 , 0x00 , 0x03 , 0x00 , 0x00 , 0x29 , (byte) 0xC5
            };
            byte[] open1 = new byte[] {
                    (byte) 0xFE, 0x05 , 0x00 , 0x00 , (byte) 0xFF, 0x00 , (byte) 0x98, 0x35
            };
            send(ip, close2);

            send(ip, close3);
            send(ip, close4);
            send(ip, open1);
        } catch (Exception e) {

        }

    }

    public static void send(String ip, byte[] data) {
        try {
            int port = 10000;
            Socket socket = new Socket(ip, port);
            //byte[] close1 = new byte[] {
            //        (byte) 0xFE, 0x05, 0x00,0x00, (byte) 0xFF, 0x00, (byte) 0x98, (byte) 0x35
            //};
            //byte[] open2 = new byte[] {
            //        (byte)0xFE, 0x05, 0x00, 0x01,  (byte)0xFF, 0x00, (byte) 0xC9, (byte) 0xF5
            //};
            //
            //byte[] open3 = new byte[] {
            //        (byte) 0xFE, 0x05, 0x00, 0x02, (byte) 0xFF, 0x00, 0x39, (byte) 0xF5
            //};
            //
            //byte[] open4 = new byte[] {
            //        (byte) 0xFE, 0x05, 0x00, 0x03, 0x00, 0x00, 0x29, (byte) 0xC5
            //};
            socket.setSoTimeout(60000);
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            out.write(data);
            out.close();
            socket.close();
        } catch (Exception e) {

        }
    }

    // 关闭通道1
    // FE 05 00 00 00 00 D9 C5

    // 打开通道1
    // FE 05 00 00 00 FF 00 98 35

    // 关2
    // FE 05 00 01 00 00 88 05
    // 开2
    // FE 05 00 01 FF 00 C9 F5


    // 关3
    // FE 05 00 02 00 00 78 05
    // 开3
    // FE 05 00 02 FF 00 39 F5

    // 开4
    // FE 05 00 03 FF 00 68 35
    // 关4
    // FE 05 00 03 00 00 29 C5
}
